<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/gray/window.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css" />
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
		<script type="text/javascript" src="../../../JS/BasicInfomation.js"></script>
	</head>

	<body style="padding: 0px;">
		<form id="ff" method="post">
			<table cellpadding="3" class="displaytable" style="padding: 20px;">
				<tr>
					<td>
						<h id="star">* </h>父节点ID</td>
					<td>
						<input style="width:90%;height:25px" class="easyui-textbox" id="input_PARENT_ID" name="PARENT_ID" data-options="readonly:true"></input>
					</td>
				</tr>
				<tr>
					<td width="30%">
						<h id="star">* </h>菜单名称
					</td>
					<td width="65%">
						<input id="input_MENU_NAME" class="easyui-textbox" name="MENU_NAME" style="width:90%;height:25px" data-options="required:true"></input>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>链接地址</td>
					<td>
						<input id="input_MENU_URL" class="easyui-textbox" name="MENU_URL" style="width:90%;height:50px" multiline="true"></input>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>菜单图标</td>
					<td>
						<input class="easyui-textbox" name="MENU_ICON" style="width:90%;height:25px"></input>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>菜单级别</td>
					<td>
						<input class="easyui-textbox" name="MENU_TYPE" style="width:90%;height:25px" data-options="required:true"></input>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>菜单模块</td>
					<td>
						<input class="easyui-textbox" name="MENU_ORDER" style="width:90%;height:25px"></input>
					</td>
				</tr>
				<tr class="hiddentr">
					<td width="30%">
						<h id="star">* </h>菜单ID
					</td>
					<td width="65%">
						<input class="easyui-textbox" name="ID" style="width:90%;height:25px" data-options="readonly:true"></input>
					</td>
				</tr>
			</table>
			<table>
				<div class="submit_button">
					<input  class="easyui-linkbutton" onclick="save()" style="width: 100px;" type="button" value="保存" />
					<input  class="easyui-linkbutton" onclick="cls()" style="width: 100px;margin-left: 10px;" type="button" value="清空" />
				</div>
			</table>
		</form>
		<div id="dlg" class="easyui-dialog" closed="true" style="width:560px;height:400px;padding:10px">
			<iframe id="ifrmEdit" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>
	<script type="text/javascript">
		var ids = getMultiID();
		$(document).ready(function(){
			if(ids.menuid != AddFlag) {
				loadRemote();
			}
		});
		$(document).ready(function() {
			$("#input_PARENT_ID").textbox('setValue', ids.parentid);
		});

		function save() {
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			SaveData();
		}

		function loadRemote() {
			var pLocation = RemoteLinkAddress + '/menu/getmenubyid.do?ID=' + ids.menuid;
			$('#ff').form('load', pLocation);
		}

		function cls() {
			$('#ff').form('reset');
		}

		function SaveData() {
			var _url = "";
			data = $('#ff').serialize();
			console.log(data);
			if(ids.menuid == AddFlag) {
				_url = RemoteLinkAddress + "/menu/save.do";
				data = data.replace("&ID=", ""); //在新增保存的时候不需要传入ID值
			} else {
				_url = RemoteLinkAddress + "/menu/update.do";
			}
			$.post(_url, data,
				function(result) {
					if(result.msg == "success") {
						var parentLocation;
						parentLocation = searchParent("MenuList.html");
						parentLocation.dialogClose();
						$.messager.alert({ // show error message
							title: '成功',
							msg: '添加成功'
						});
					} else {
						$.messager.alert({ // show error message
							title: '错误',
							msg: "输入的数据已存在数据库"
						});
					}
				},
				'json');
		}
	</script>